from django.core.files.storage import FileSystemStorage

class ImageStorage(FileSystemStorage):
    from django.conf import settings

    def __init__(self, location=settings.MEDIA_ROOT, base_url=settings.MEDIA_URL):
        super(ImageStorage, self).__init__(location, base_url)

    def _save(self, name, content):
        import os, time, random, md5
        ext = os.path.splitext(name)[1]
        tmp = md5.new(name)
        tmp.update(str(time.time()))
        fn = tmp.hexdigest()
        name = os.path.join(fn[0], fn[1], fn[2:] + ext)
        return super(ImageStorage, self)._save(name, content)

